package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.server.mapper.BlackListMapper;
import com.tanhua.server.pojo.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;

    public IPage<BlackList> queryBlacklist(Long userId, Integer page, Integer pageSize) {
        QueryWrapper<BlackList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.orderByDesc("created");
        Page<BlackList> pager=new Page<>(page,pageSize);
        IPage<BlackList> blackListIPage = blackListMapper.selectPage(pager, queryWrapper);
        return blackListIPage;
    }

    public void delBlacklist(Long id, Long userId) {
        QueryWrapper<BlackList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id", id).eq("black_user_id", userId);
        blackListMapper.delete(queryWrapper);
    }
}
